/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;

/**
 *
 * @author Green
 */
public class MotionManager {

    ArrayList<Motion> lstMotions = new ArrayList<Motion>();

    public void addMotion_DealCard(GUICard card, Gambler targetGambler) {
        card.owner = targetGambler.getID();
        Point target = targetGambler.getNextPosition();
        Motion motion = new Motion(card, target, targetGambler, Motion.MType.Deal);
        this.lstMotions.add(motion);
    }

    public void addMotion_PlayCard(GUICard card, Gambler gambler, Banker banker) {
        card.owner = -1;
        Motion motion = new Motion(card, banker.nextPosition(gambler.getID()), banker, Motion.MType.Play);
        this.lstMotions.add(motion);
    }

    public void addMotion_TakenCard(GUICard card, Gambler targetGambler) {
        card.owner = targetGambler.getID();
        Point target = targetGambler.getNextPosition_TakenCard();
        Motion motion = new Motion(card, target, targetGambler, Motion.MType.Lose);
        this.lstMotions.add(motion);
    }

    public void update() {
        for (int i = 0; i < this.lstMotions.size(); i++) {
            Motion motion = this.lstMotions.get(i);
            motion.update();
            if (motion.isFinished()) {
                this.lstMotions.remove(motion);
                motion.notifyReceiver();
            }
        }
    }

    public void draw(Graphics g) {
        for (int i = 0; i < this.lstMotions.size(); i++) {
            Motion motion = this.lstMotions.get(i);
            motion.draw(g);
        }
    }

    public void clear() {
        this.lstMotions.clear();
    }
}
